package tools;

import controller.MessageController;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

/**
 * @Author 王志康
 * @Date 2021/9/5 17:01
 * @Version 1.0.0
 */
public class UtilMessage extends Application {
    private final Stage stage = new Stage();
    private String message;

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(UtilMessage.class.getClassLoader().getResource("fxml/MessageFxml.fxml"));
        Parent root = fxmlLoader.load();
        //获取预加载消息框的控制类实例
        MessageController controller=fxmlLoader.getController();
        controller.setMessage(message);
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }

    /**
     * 弹出消息框
     *
     * @param message 要显示的消息
     */
    public void messageShow(String message) {
        this.message = message;
        try {
            //设置窗口为消息提示风格
            stage.initStyle(StageStyle.UNDECORATED);
            //窗口不可改变
            stage.setResizable(false);
            //窗口始终置顶
            stage.setAlwaysOnTop(true);
            start(stage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
